package org.annotationz.util;

/**
 * 驼峰转大写 字符间用下划线分割
 */
public class UpperCaseWithUnderscoreUtils {

    public static String toUpperCaseWithUnderscore(String input) {
        if (input == null || input.isEmpty()) {
            return input;
        }

        StringBuilder upperCaseWithUnderscore = new StringBuilder();

        for (int i = 0; i < input.length(); i++) {
            char currentChar = input.charAt(i);

            if (Character.isUpperCase(currentChar) && i > 0) {
                upperCaseWithUnderscore.append('_');
            }

            upperCaseWithUnderscore.append(Character.toUpperCase(currentChar));
        }

        return upperCaseWithUnderscore.toString();
    }
}
